package com.pearadmin.modules.sys.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pearadmin.common.tools.SequenceUtil;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.modules.sys.domain.*;
import com.pearadmin.modules.sys.mapper.WorkCastingMapper;
import com.pearadmin.modules.sys.mapper.WorkOrderHistoryMapper;
import com.pearadmin.modules.sys.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.session.SessionRegistry;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工单历史管理Service业务层处理
 *
 * @author Mr.Ling
 * @date 2021-12-18
 */
@Service
@Slf4j
public class WorkOrderHistoryServiceImpl implements IWorkOrderHistoryService {
    @Autowired
    private WorkOrderHistoryMapper workOrderHistoryMapper;
    /**
     * 查询工单管理
     *
     * @param id 工单管理ID
     * @return 工单管理
     */
    @Override
    public WorkOrderHistory selectWorkOrderHistoryById(String id) {
        return workOrderHistoryMapper.selectWorkOrderHistoryById(id);
    }

    /**
     * 查询工单管理列表
     *
     * @param workOrderHistory 工单管理
     * @return 工单管理
     */
    @Override
    public List<WorkOrderHistory> selectWorkOrderHistoryList(WorkOrderHistory workOrderHistory) {
        return workOrderHistoryMapper.selectWorkOrderHistoryList(workOrderHistory);
    }

    /**
     * 查询工单管理
     *
     * @param workOrderHistory  工单管理
     * @param pageDomain
     * @return 工单管理 分页集合
     */
    @Override
    public PageInfo<WorkOrderHistory> selectWorkOrderHistoryPage(WorkOrderHistory workOrderHistory, PageDomain pageDomain) {
        PageHelper.startPage(pageDomain.getPage(), pageDomain.getLimit());
        List<WorkOrderHistory> data = workOrderHistoryMapper.selectWorkOrderHistoryList(workOrderHistory);
        return new PageInfo<>(data);
    }

    /**
     * 新增工单管理
     *
     * @param workOrder 工单管理
     * @return 结果
     */
    @Override
    @Transactional
    public int insertWorkOrderHistory(WorkOrder workOrder) {
        WorkOrderHistory history = new WorkOrderHistory();
        BeanUtils.copyProperties(workOrder, history);
        history.setOrderId(history.getId());
        history.setId(SequenceUtil.makeStringId());
        return workOrderHistoryMapper.insertWorkOrderHistory(history);
    }


    /**
     * 修改工单管理
     *
     * @param workOrderHistory 工单管理
     * @return 结果
     */
    @Override
    @Transactional
    public int updateWorkOrderHistory(WorkOrderHistory workOrderHistory) {
        return workOrderHistoryMapper.updateWorkOrderHistory(workOrderHistory);
    }


    /**
     * 删除工单管理对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWorkOrderHistoryByIds(String[] ids) {
        return workOrderHistoryMapper.deleteWorkOrderHistoryByIds(ids);
    }

    /**
     * 删除工单管理信息
     *
     * @param id 工单管理ID
     * @return 结果
     */
    @Override
    public int deleteWorkOrderHistoryById(String id) {
        return workOrderHistoryMapper.deleteWorkOrderHistoryById(id);
    }
}
